﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace SQLTouch.Service.DataContracts
{
    [DataContract]
    public struct TableNameData : IEquatable<TableNameData>
    {
        [DataMember]
        private readonly string catalog;
        [DataMember]
        private readonly string schema;
        [DataMember]
        private readonly string name;

        public TableNameData(string catalog, string schema, string name)
        {
            this.catalog = catalog;
            this.schema = schema;
            this.name = name;
        }

        public string Catalog
        {
            get { return catalog; }
        }

        public string Schema
        {
            get { return schema; }
        }

        public string Name
        {
            get { return name; }
        }

        public bool Equals(TableNameData other)
        {
            return catalog == other.catalog && schema == other.schema && name == other.name;
        }

        public override bool Equals(object obj)
        {
            if (obj is TableNameData)
            {
                return Equals((TableNameData)obj);
            }
            else
            {
                return false;
            }
        }

        public override int GetHashCode()
        {
            return (catalog == null ? 0 : catalog.GetHashCode()) ^ (schema == null ? 0 : schema.GetHashCode()) ^ (name == null ? 0 : name.GetHashCode());
        }

        public override string ToString()
        {
            return "[" + Catalog + "].[" + Schema + "].[" + Name + "]";
        }

        public static bool operator ==(TableNameData left, TableNameData right)
        {
            return left.Equals(right);
        }

        public static bool operator !=(TableNameData left, TableNameData right)
        {
            return !(left == right);
        }
    }
}
